/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.DMBean;
import com.postek.coyote.postekwifi.bean.LabelBean;

import java.util.ArrayList;

/**
 * @author yrwang
 *
 */
public class PrintDMActivity extends AppCompatActivity {

	private CDFPTKAndroid cdf = MainActivity.cdf;
	private ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;
	
	private Button btnPrint = null;
	private Button btnCancel = null;
	
	private EditText et_DM1 = null;
	private EditText et_DM2 = null;
	private EditText et_DM3 = null;
	private EditText et_DM4 = null;
	private Spinner sp_DM5 = null;
	private Spinner sp_DM6 = null;
	private EditText et_DMS = null;
	private EditText et_print_number=null;
	private EditText et_print_cpnumber=null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.print_dm);
		
		btnPrint = (Button) findViewById(R.id.btn_printDM_print);
		btnCancel = (Button) findViewById(R.id.btn_printDM_cancel);
		
		et_DM1 = (EditText) findViewById(R.id.et_print_DM1);
		et_DM2 = (EditText) findViewById(R.id.et_print_DM2);
		et_DM3 = (EditText) findViewById(R.id.et_print_DM3);
		et_DM4 = (EditText) findViewById(R.id.et_print_DM4);
		sp_DM5 = (Spinner) findViewById(R.id.sp_print_DM5);
		sp_DM6 = (Spinner) findViewById(R.id.sp_print_DM6);
		et_DMS = (EditText) findViewById(R.id.et_print_DMS);
		et_print_number= (EditText) findViewById(R.id.et_print_number);
		et_print_cpnumber= (EditText) findViewById(R.id.et_print_cpnumber);

		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		btnPrint.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iDM1 = 0;
				int iDM2 = 0;
				int iDM3 = 0;
				int iDM4 = 0;
				int iDM5 = sp_DM5.getSelectedItemPosition();
				int iDM6 = sp_DM6.getSelectedItemPosition() + 1;
				String iDMS = et_DMS.getText().toString();

				int number=Integer.parseInt(et_print_number.getText().toString());
				int cpnumber=Integer.parseInt(et_print_cpnumber.getText().toString());
				
				if(!("".equals(et_DM1.getText().toString()))){
					iDM1 = Integer.parseInt(et_DM1.getText().toString());
				}
				
				if(!("".equals(et_DM2.getText().toString()))){
					iDM2 = Integer.parseInt(et_DM2.getText().toString());
				}
				
				if(!("".equals(et_DM3.getText().toString()))){
					iDM3 = Integer.parseInt(et_DM3.getText().toString());
				}
				
				if(!("".equals(et_DM4.getText().toString()))){
					iDM4 = Integer.parseInt(et_DM4.getText().toString());
				}
				
				int nReturn = cdf.PTK_DrawBar2D_DATAMATRIX(iDM1, iDM2, iDM3, iDM4, iDM5, iDM6, iDMS);
				
				if (nReturn == 0) {
					DMBean bean = new DMBean(iDM1, iDM2, iDM3, iDM4, iDM5, iDM6, iDMS);
					labelBeans.add(bean);
					Toast.makeText(PrintDMActivity.this, R.string.setting_success, Toast.LENGTH_SHORT).show();
					cdf.PTK_PrintLabel(number,cpnumber);
				} else {
					Toast.makeText(PrintDMActivity.this,  R.string.setting_fail, Toast.LENGTH_SHORT).show();
				}
			}
		});
	}
	
}
